package com.hnevc.kaoshitest1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.hnevc.kaoshitest1.adapter.MyAdapter;

public class MainActivity extends AppCompatActivity {

    private ListView newsLv;
    private String[] titles;
    private String[] timeArray;
    private String[] contentArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        newsLv = findViewById(R.id.news_listview);
    }

    private void initData() {
        titles = new String[]{"中国共产党成立100周年","疫苗接种人数突破12亿"};
        timeArray = new String[]{"2021年07月01日","2021年06月30日"};
        contentArray = new String[]{"中国共产党成立100周年大会在北京天安门广场召开","疫苗接种人数突破12亿,没打的赶紧打"};
        newsLv.setAdapter(new MyAdapter(MainActivity.this, titles, timeArray));
    }

    private void initEvent() {
        newsLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MainActivity.this,NewsDetailActivity.class);
                intent.putExtra("title",titles[position]);
                intent.putExtra("time",timeArray[position]);
                intent.putExtra("content",contentArray[position]);
                startActivity(intent);
            }
        });
    }
}